package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyDbdkYingfu;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyDbdkYingfuMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDbdkYingfuParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyDbdkYingfuResult;
import  cn.stylefeng.guns.sys.modular.system.service.BtyDbdkYingfuService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuy
 * @since 2022-03-14
 */
@Service
public class BtyDbdkYingfuServiceImpl extends ServiceImpl<BtyDbdkYingfuMapper, BtyDbdkYingfu> implements BtyDbdkYingfuService {

    @Override
    public void add(BtyDbdkYingfuParam param){
        BtyDbdkYingfu entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyDbdkYingfuParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyDbdkYingfuParam param){
        BtyDbdkYingfu oldEntity = getOldEntity(param);
        BtyDbdkYingfu newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyDbdkYingfuResult findBySpec(BtyDbdkYingfuParam param){
        return null;
    }

    @Override
    public List<BtyDbdkYingfuResult> findListBySpec(BtyDbdkYingfuParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyDbdkYingfuParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public boolean insertDbdk(List<BtyDbdkYingfu> list) {
        return baseMapper.insertDbdk(list);
    }

    @Override
    public List<BtyDbdkYingfuResult> dbdkList() {
        return baseMapper.dbdkList();
    }

    @Override
    public List<BtyDbdkYingfuResult> customList(BtyDbdkYingfuParam param) {
        return baseMapper.customList(param);
    }

    private Serializable getKey(BtyDbdkYingfuParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyDbdkYingfu getOldEntity(BtyDbdkYingfuParam param) {
        return this.getById(getKey(param));
    }

    private BtyDbdkYingfu getEntity(BtyDbdkYingfuParam param) {
        BtyDbdkYingfu entity = new BtyDbdkYingfu();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
